package it.polimi.digitalstate.entities;

import it.polimi.digitalstate.dto.IDataTransferObject;
import it.polimi.digitalstate.entities.Citizen;
import it.polimi.digitalstate.entities.Party;
import it.polimi.digitalstate.manager.DTOEntityTransformer;

import java.io.Serializable;
import java.lang.String;
import java.sql.Date;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

import it.polimi.digitalstate.dto.JoinrequestDTO;
/**
 * Entity implementation class for Entity: joinrequest
 *
 */
@Entity
@NamedQueries(value = { 
		@NamedQuery(name = "joinrequest_getByID", query = "select j from Joinrequest j where j.id = :id" ),
		@NamedQuery(name = "joinrequest_getByCitizen", query = "select j from Joinrequest j where j.citizen = :citizen" ),
		@NamedQuery(name = "joinrequest_getAllByParty", query = "select j from Joinrequest j where j.party = :party" ),
		@NamedQuery(name = "joinrequest_getByElection", query = "select j from Joinrequest j where j.election = :election" ),
		
	})
		@Table(uniqueConstraints= @UniqueConstraint(columnNames = {"citizen", "election"})) /*only one request per election*/ 
public class Joinrequest implements Serializable , IEntity {
	//TODO create the DTO
	//TODO set a Constructor with a DTO and set a method that retrive the DTO
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	@JoinColumn(nullable=false)
	private Citizen citizen;
	@JoinColumn(nullable=false)
	private Party party;
	@JoinColumn(nullable=false)
	private Election election;
	private String cv;
	@Lob 
	@Column(nullable=false, name="letter", length=512)
	private String letter;
	private Date request_date;
	private static final long serialVersionUID = 1L;

	public Joinrequest() {
		super();
	}   
	public Joinrequest(Party party, Citizen citizen,Election election, String cv, String letter, Date request_date){
		super();
		this.party=party;
		this.citizen=citizen;
		this.election=election;
		this.cv=cv;
		this.letter=letter;
		this.request_date=request_date;
	}
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}   
	public Citizen getCitizen() {
		return this.citizen;
	}

	public void setCitizen(Citizen citizen) {
		this.citizen = citizen;
	}   
	public Party getParty() {
		return this.party;
	}

	public void setParty(Party party) {
		this.party = party;
	}   
	public String getCv() {
		return this.cv;
	}

	public void setCv(String cv) {
		this.cv = cv;
	}   
	public String getLetter() {
		return this.letter;
	}

	public void setLetter(String letter) {
		this.letter = letter;
	}   
	public Date getRequest_date() {
		return this.request_date;
	}

	public void setRequest_date(Date request_date) {
		this.request_date = request_date;
	}
	@Override
	public IDataTransferObject getDTO() {
		return new JoinrequestDTO(id, citizen.getDTO(), party.getDTO(), cv, letter, request_date);
	}
	public Election getElection() {
		return election;
	}
	public void setElection(Election election) {
		this.election = election;
	}
   
}
